//
//  YPCrypto.swift
//  YourPassword
//
//  Created by 李冲 on 15/11/24.
//  Copyright © 2015年 Saye. All rights reserved.
//

import Foundation

class YPCrypto: NSObject {
    static func SHA256(target: String) -> [UInt8]? {
        if let originData = target.dataUsingEncoding(NSUTF8StringEncoding) {
            var hash = [UInt8](count: Int(CC_SHA256_DIGEST_LENGTH), repeatedValue: 0)
            CC_SHA256(originData.bytes, CC_LONG(originData.length), &hash)
            return hash
        }
        return nil
    }
    
    static func MD5(target: String) -> [UInt8]? {
        if let data = target.dataUsingEncoding(NSUTF8StringEncoding) {
            var hash = [UInt8](count: Int(CC_MD5_DIGEST_LENGTH), repeatedValue: 0)
            CC_MD5(data.bytes, CC_LONG(data.length), &hash)
            return hash
        }
        return nil
    }
}
